package ui

import (
	"fyne.io/fyne/v2"
)

type AlistLayout struct {
	a *Alist
}

func (a *AlistLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
	var top float32 = 10
	var left float32 = 5

	a.a.start.Resize(a.a.start.MinSize())
	a.a.restart.Resize(a.a.restart.MinSize())
	a.a.stop.Resize(a.a.stop.MinSize())

	a.a.storage.Resize(a.a.storage.MinSize())
	a.a.resetPassword.Resize(a.a.resetPassword.MinSize())
	a.a.admin.Resize(a.a.admin.MinSize())

	a.a.version.Resize(a.a.version.MinSize())
	a.a.outLabel.Resize(a.a.outLabel.MinSize())

	a.a.start.Move(fyne.NewPos(top, top))
	a.a.stop.Move(fyne.NewPos(top+a.a.start.Size().Width+left, top))
	a.a.restart.Move(fyne.NewPos(top+a.a.start.Size().Width+a.a.start.Size().Width+left*2, top))

	a.a.resetPassword.Move(fyne.NewPos(top,
		top+a.a.start.Size().Width+left))
	a.a.storage.Move(fyne.NewPos(top+a.a.start.Size().Width+left,
		top+a.a.start.Size().Width+left))
	a.a.admin.Move(fyne.NewPos(top+a.a.start.Size().Width+a.a.start.Size().Width+left*2,
		top+a.a.start.Size().Width+left))

	// 输出界面
	a.a.outScroll.Resize(fyne.NewSize(size.Width*0.6, size.Height*0.6))
	// a.a.outScroll.Move(fyne.NewPos(size.Width-a.a.outLabel.MinSize().Width, top+a.a.start.Size().Width+left*2))

}

func (a *AlistLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
	minsize := fyne.NewSize(0, 0)

	minsize.Height = a.a.start.MinSize().Height +
		a.a.outLabel.MinSize().Height +
		a.a.version.MinSize().Height

	minsize.Width = a.a.start.MinSize().Width * 3

	return minsize
}
